
##################################################
# Profile: Three-Way Interactions 
##################################################

# specify a list one standard deviation from the standardized mea
list<- list(neg_id_mean=c(-1.035, 0.739, # uninterested
                          -0.945, 1.215) # interested
            , pos_id_mean=c(-1.355, 0.045, # uninterested
                            -0.25, 1.444), # interested
            InterestedNum=c("0","1")) 

# Age ----
Mage<-lm(age ~ 
               Analysis+
               InterestedNum+
               InterestedNum*pos_id_mean*neg_id_mean , # 3 way interaction
             data = meta_std) # data frame with only interested 
summary(Mage)

# create interaction data frame
#inter_age <- emmip(Mage,neg_id_mean~pos_id_mean~InterestedNum,at=list, CIs=TRUE, PIs=TRUE, plotit = FALSE)
#inter_age$combination<-paste(inter_age$xvar,inter_age$tvar, sep = " ") # combine conditions

#inter_age_keep<-inter_age%>%
#  dplyr::select(., combination,yvar)%>%
#  pivot_wider(names_from = "combination", values_from = "yvar")
#inter_age_keep$DV<- "Age"

inter_age_keep<-emmip(Mage, neg_id_mean ~ pos_id_mean ~ InterestedNum, 
      at = list, CIs = TRUE, PIs = TRUE, plotit = FALSE) %>%
  mutate(
    combi_pos = paste(InterestedNum,pos_id_mean, sep = " "),
    combi_neg= paste(InterestedNum,neg_id_mean, sep = " "),
    DV = "Age") %>% # add new colomn for DV
  rename(EMM = yvar, CI_lower = LCL, CI_upper = UCL)

# 2. Gender ----
Mgender<-lm(sex_fem ~ 
           Analysis+
           InterestedNum+
           InterestedNum*pos_id_mean*neg_id_mean , # 3 way interaction
         data = meta_std) # data frame with only interested 
summary(Mgender)

# create interaction data frame
#inter_gender <- emmip(Mgender,neg_id_mean~pos_id_mean~InterestedNum,at=list, CIs=TRUE, PIs=TRUE, plotit = FALSE)
#inter_gender$combination<-paste(inter_gender$xvar,inter_gender$tvar, sep = " ") # combine conditions

#inter_gender_keep<-inter_gender%>%
#  dplyr::select(., combination,yvar)%>%
#  pivot_wider(names_from = "combination", values_from = "yvar")
#inter_gender_keep$DV<- "Female"

inter_gender_keep<-emmip(Mgender, neg_id_mean ~ pos_id_mean ~ InterestedNum, 
                 at = list, CIs = TRUE, PIs = TRUE, plotit = FALSE) %>%
  mutate(
    combi_pos = paste(InterestedNum,pos_id_mean, sep = " "),
    combi_neg= paste(InterestedNum,neg_id_mean, sep = " "),
    DV = "Female") %>% # add new colomn for DV
  rename(EMM = yvar, CI_lower = LCL, CI_upper = UCL)

# 3. Education ----
# --- create dummy:
meta_std <- meta_std %>% # numeric
  mutate(
    education_dummy = case_when(education == "VMBO"~0, # put lagere and VMBO together
                              education == "HAVO_VW_Gymnasium"~0, 
                              education == "MBO"~0, 
                              education == "HBO" ~1, 
                              education ==  "Universiteit" ~ 1, 
                              education == "Lagere_School"~0, TRUE ~ NA))

meta_std$education_dummy<-as.numeric(meta_std$education_dummy)

Meducation<-lm(education_dummy ~ 
              Analysis+
              InterestedNum+
              InterestedNum*pos_id_mean*neg_id_mean , # 3 way interaction
            data = meta_std) # data frame with only interested 
summary(Meducation)

# create interaction data frame
#inter_edu <- emmip(Meducation,neg_id_mean~pos_id_mean~InterestedNum,at=list, CIs=TRUE, PIs=TRUE, plotit = FALSE)
#inter_edu$combination<-paste(inter_edu$xvar,inter_edu$tvar, sep = " ") # combine conditions

#inter_edu_keep<-inter_edu%>%
#  dplyr::select(., combination,yvar)%>%
#  pivot_wider(names_from = "combination", values_from = "yvar")
#inter_edu_keep$DV<- "Education"

inter_edu_keep<-emmip(Meducation, neg_id_mean ~ pos_id_mean ~ InterestedNum, 
                         at = list, CIs = TRUE, PIs = TRUE, plotit = FALSE) %>%
  mutate(
    combi_pos = paste(InterestedNum,pos_id_mean, sep = " "),
    combi_neg= paste(InterestedNum,neg_id_mean, sep = " "),
    DV = "Education") %>% # add new colomn for DV
  rename(EMM = yvar, CI_lower = LCL, CI_upper = UCL)

# 4. Big 5 ----
MpersA<-lm(a ~ 
             Analysis+
             InterestedNum+
             InterestedNum*pos_id_mean*neg_id_mean , # 3 way interaction
           data = meta_std) # data frame with only interested 
summary(MpersA)

# create interaction data frame
#inter_A <- emmip(MpersA,neg_id_mean~pos_id_mean~InterestedNum,at=list, CIs=TRUE, PIs=TRUE, plotit = FALSE)
#inter_A$combination<-paste(inter_A$xvar,inter_A$tvar, sep = " ") # combine conditions

#inter_A_keep<-inter_A%>%
#  dplyr::select(., combination,yvar)%>%
#  pivot_wider(names_from = "combination", values_from = "yvar")
#inter_A_keep$DV<- "Agreeableness"

inter_A_keep<-emmip(MpersA, neg_id_mean ~ pos_id_mean ~ InterestedNum, 
                      at = list, CIs = TRUE, PIs = TRUE, plotit = FALSE) %>%
  mutate(
    combi_pos = paste(InterestedNum,pos_id_mean, sep = " "),
    combi_neg= paste(InterestedNum,neg_id_mean, sep = " "),
    DV = "Agreeableness") %>% # add new colomn for DV
  rename(EMM = yvar, CI_lower = LCL, CI_upper = UCL)

MpersN<-lm(n ~ 
             Analysis+
             InterestedNum+
             InterestedNum*pos_id_mean*neg_id_mean , # 3 way interaction
           data = meta_std) # data frame with only interested 
summary(MpersN)

# create interaction data frame
#inter_N <- emmip(MpersN,neg_id_mean~pos_id_mean~InterestedNum,at=list, CIs=TRUE, PIs=TRUE, plotit = FALSE)
#inter_N$combination<-paste(inter_N$xvar,inter_N$tvar, sep = " ") # combine conditions

#inter_N_keep<-inter_N%>%
#  dplyr::select(., combination,yvar)%>%
#  pivot_wider(names_from = "combination", values_from = "yvar")
#inter_N_keep$DV<- "Neuroticism"

inter_N_keep<-emmip(MpersN, neg_id_mean ~ pos_id_mean ~ InterestedNum, 
                    at = list, CIs = TRUE, PIs = TRUE, plotit = FALSE) %>%
  mutate(
    combi_pos = paste(InterestedNum,pos_id_mean, sep = " "),
    combi_neg= paste(InterestedNum,neg_id_mean, sep = " "),
    DV = "Neuroticism") %>% # add new colomn for DV
  rename(EMM = yvar, CI_lower = LCL, CI_upper = UCL)

MpersO<-lm(o ~ 
             Analysis+
             InterestedNum+
             InterestedNum*pos_id_mean*neg_id_mean , # 3 way interaction
           data = meta_std) # data frame with only interested 
summary(MpersO)

# create interaction data frame
#inter_O <- emmip(MpersO,neg_id_mean~pos_id_mean~InterestedNum,at=list, CIs=TRUE, PIs=TRUE, plotit = FALSE)
#inter_O$combination<-paste(inter_O$xvar,inter_O$tvar, sep = " ") # combine conditions

#inter_O_keep<-inter_O%>%
#  dplyr::select(., combination,yvar)%>%
#  pivot_wider(names_from = "combination", values_from = "yvar")
#inter_O_keep$DV<- "Openness"

inter_O_keep<-emmip(MpersO, neg_id_mean ~ pos_id_mean ~ InterestedNum, 
                    at = list, CIs = TRUE, PIs = TRUE, plotit = FALSE) %>%
  mutate(
    combi_pos = paste(InterestedNum,pos_id_mean, sep = " "),
    combi_neg= paste(InterestedNum,neg_id_mean, sep = " "),
    DV = "Openness") %>% # add new colomn for DV
  rename(EMM = yvar, CI_lower = LCL, CI_upper = UCL)

MpersC<-lm(c ~ 
             Analysis+
             InterestedNum+
             InterestedNum*pos_id_mean*neg_id_mean , # 3 way interaction
           data = meta_std) # data frame with only interested 
summary(MpersC)

# create interaction data frame
#inter_C <- emmip(MpersC,neg_id_mean~pos_id_mean~InterestedNum,at=list, CIs=TRUE, PIs=TRUE, plotit = FALSE)
#inter_C$combination<-paste(inter_C$xvar,inter_C$tvar, sep = " ") # combine conditions

#inter_C_keep<-inter_C%>%
#  dplyr::select(., combination,yvar)%>%
#  pivot_wider(names_from = "combination", values_from = "yvar")
#inter_C_keep$DV<- "Conscientiousness"

inter_C_keep<-emmip(MpersC, neg_id_mean ~ pos_id_mean ~ InterestedNum, 
                    at = list, CIs = TRUE, PIs = TRUE, plotit = FALSE) %>%
  mutate(
    combi_pos = paste(InterestedNum,pos_id_mean, sep = " "),
    combi_neg= paste(InterestedNum,neg_id_mean, sep = " "),
    DV = "Conscientiousness") %>% # add new colomn for DV
  rename(EMM = yvar, CI_lower = LCL, CI_upper = UCL)

MpersE<-lm(e ~ 
             Analysis+
             InterestedNum+
             InterestedNum*pos_id_mean*neg_id_mean , # 3 way interaction
           data = meta_std) # data frame with only interested 
summary(MpersE)

# create interaction data frame
#inter_E <- emmip(MpersE,neg_id_mean~pos_id_mean~InterestedNum,at=list, CIs=TRUE, PIs=TRUE, plotit = FALSE)
#inter_E$combination<-paste(inter_E$xvar,inter_E$tvar, sep = " ") # combine conditions

#inter_E_keep<-inter_E%>%
#  dplyr::select(., combination,yvar)%>%
#  pivot_wider(names_from = "combination", values_from = "yvar")
#inter_E_keep$DV<- "Extroversion"

inter_E_keep<-emmip(MpersE, neg_id_mean ~ pos_id_mean ~ InterestedNum, 
                   at = list, CIs = TRUE, PIs = TRUE, plotit = FALSE) %>%
  mutate(
    combi_pos = paste(InterestedNum,pos_id_mean, sep = " "),
    combi_neg= paste(InterestedNum,neg_id_mean, sep = " "),
    DV = "Extroversion") %>% # add new colomn for DV
  rename(EMM = yvar, CI_lower = LCL, CI_upper = UCL)

# 6. Self-esteem ----
Mselfest<-lm(self_esteem ~ 
               Analysis+
               InterestedNum+
               InterestedNum*pos_id_mean*neg_id_mean , # 3 way interaction
             data = meta_std) # data frame with only interested 
summary(Mselfest)

# create interaction data frame
#inter_selfest <- emmip(Mselfest,neg_id_mean~pos_id_mean~InterestedNum,at=list, CIs=TRUE, PIs=TRUE, plotit = FALSE)
#inter_selfest$combination<-paste(inter_selfest$xvar,inter_selfest$tvar, sep = " ") # combine conditions

#inter_selfest_keep<-inter_selfest%>%
#  dplyr::select(., combination,yvar)%>%
 # pivot_wider(names_from = "combination", values_from = "yvar")
#inter_selfest_keep$DV<- "Self-esteem"

inter_selfest_keep<-emmip(Mselfest, neg_id_mean ~ pos_id_mean ~ InterestedNum, 
                    at = list, CIs = TRUE, PIs = TRUE, plotit = FALSE) %>%
  mutate(
    combi_pos = paste(InterestedNum,pos_id_mean, sep = " "),
    combi_neg= paste(InterestedNum,neg_id_mean, sep = " "),
    DV = "Self-esteem") %>% # add new colomn for DV
  rename(EMM = yvar, CI_lower = LCL, CI_upper = UCL)


# 7. NFC ----
Mpersnfc<-lm(nfc ~ 
               Analysis+
               InterestedNum+
               InterestedNum*pos_id_mean*neg_id_mean , # 3 way interaction
             data = meta_std) # data frame with only interested 
summary(Mpersnfc)

# create interaction data frame
inter_nfc <- emmip(Mpersnfc,neg_id_mean~pos_id_mean~InterestedNum,at=list, CIs=TRUE, PIs=TRUE, plotit = FALSE)
inter_nfc$combination<-paste(inter_nfc$xvar,inter_nfc$tvar, sep = " ") # combine conditions

inter_nfc_keep<-inter_nfc%>%
  dplyr::select(., combination,yvar)%>%
  pivot_wider(names_from = "combination", values_from = "yvar")
inter_nfc_keep$DV<- "NFC"

# 8. NFA ----
Mpersnfa<-lm(nfa ~ 
               Analysis+
               InterestedNum+
               InterestedNum*pos_id_mean*neg_id_mean , # 3 way interaction
             data = meta_std) # data frame with only interested 
summary(Mpersnfa)

# create interaction data frame
inter_nfa <- emmip(Mpersnfa,neg_id_mean~pos_id_mean~InterestedNum,at=list, CIs=TRUE, PIs=TRUE, plotit = FALSE)
inter_nfa$combination<-paste(inter_nfa$xvar,inter_nfa$tvar, sep = " ") # combine conditions

inter_nfa_keep<-inter_nfa%>%
  dplyr::select(., combination,yvar)%>%
  pivot_wider(names_from = "combination", values_from = "yvar")
inter_nfa_keep$DV<- "NFA"

# 9. SDO ----
Mperssdo<-lm(sdo ~ 
               Analysis+
               InterestedNum+
               InterestedNum*pos_id_mean*neg_id_mean , # 3 way interaction
             data = meta_std) # data frame with only interested 
summary(Mperssdo)

# create interaction data frame
inter_sdo <- emmip(Mperssdo,neg_id_mean~pos_id_mean~InterestedNum,at=list, CIs=TRUE, PIs=TRUE, plotit = FALSE)
inter_sdo$combination<-paste(inter_sdo$xvar,inter_sdo$tvar, sep = " ") # combine conditions

inter_sdo_keep<-inter_sdo%>%
  dplyr::select(., combination,yvar)%>%
  pivot_wider(names_from = "combination", values_from = "yvar")
inter_sdo_keep$DV<- "SDO"

# 9. Dogmatism ----
Mpersdog<-lm(dogmatism ~ 
               Analysis+
               InterestedNum+
               InterestedNum*pos_id_mean*neg_id_mean , # 3 way interaction
             data = meta_std) # data frame with only interested 
summary(Mpersdog)

# create interaction data frame
inter_dog <- emmip(Mpersdog,neg_id_mean~pos_id_mean~InterestedNum,at=list, CIs=TRUE, PIs=TRUE, plotit = FALSE)
inter_dog$combination<-paste(inter_dog$xvar,inter_dog$tvar, sep = " ") # combine conditions

inter_dog_keep<-inter_dog%>%
  dplyr::select(., combination,yvar)%>%
  pivot_wider(names_from = "combination", values_from = "yvar")
inter_dog_keep$DV<- "Dogmatism"




